/*
 * @lc app=leetcode.cn id=349 lang=rust
 *
 * [349] 两个数组的交集
 */

// @lc code=start
impl Solution {
    pub fn intersection(nums1: Vec<i32>, nums2: Vec<i32>) -> Vec<i32> {
        use std::collections::HashSet;
        let mut set = HashSet::new();
        let mut set2 = HashSet::new();

        let mut ret = Vec::new();
        for i in nums1.iter() {
            set.insert(i);
        }
        for j in nums2.iter(){
            if set.contains(j) {
                set2.insert(j);
            }
        }

        for i in set2.iter() {
            ret.push(**i);
        }

        return ret;
    }
}
// @lc code=end

